package btcbot.entities;

import net.sf.json.JSONObject;

public class Wallet {

	private Currency currency;
	private Double balance;
	private Double openOrderAmount;
	private Integer openOrderNb;

	public Wallet() {
		super();
	}

	public Wallet(JSONObject jsonWallet) {
		super();
		this.currency = Currency.valueOf(jsonWallet.getJSONObject("Balance").getString("currency"));
		this.balance = jsonWallet.getJSONObject("Balance").getDouble("value");
		this.openOrderAmount = jsonWallet.getJSONObject("Open_Orders").getDouble("value");
		this.openOrderNb = jsonWallet.getJSONObject("Open_Orders").getInt("value_int");
	}

	public Currency getCurrency() {
		return currency;
	}

	public void setCurrency(Currency currency) {
		this.currency = currency;
	}

	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public Double getOpenOrderAmount() {
		return openOrderAmount;
	}

	public void setOpenOrderAmount(Double openOrderAmount) {
		this.openOrderAmount = openOrderAmount;
	}

	public Integer getOpenOrderNb() {
		return openOrderNb;
	}

	public void setOpenOrderNb(Integer openOrderNb) {
		this.openOrderNb = openOrderNb;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((balance == null) ? 0 : balance.hashCode());
		result = prime * result + ((currency == null) ? 0 : currency.hashCode());
		result = prime * result + ((openOrderAmount == null) ? 0 : openOrderAmount.hashCode());
		result = prime * result + ((openOrderNb == null) ? 0 : openOrderNb.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Wallet other = (Wallet) obj;
		if (balance == null) {
			if (other.balance != null)
				return false;
		} else if (!balance.equals(other.balance))
			return false;
		if (currency == null) {
			if (other.currency != null)
				return false;
		} else if (!currency.equals(other.currency))
			return false;
		if (openOrderAmount == null) {
			if (other.openOrderAmount != null)
				return false;
		} else if (!openOrderAmount.equals(other.openOrderAmount))
			return false;
		if (openOrderNb == null) {
			if (other.openOrderNb != null)
				return false;
		} else if (!openOrderNb.equals(other.openOrderNb))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Wallet [" + currency + " " + balance + "; orders=(" + openOrderNb + "; " + openOrderAmount + ")]";
	}

}
